package logic

import (
	"context"
	"microdemo/internal/model/usermodel"
	"strconv"

	"microdemo/service/user/internal/svc"
	"microdemo/service/user/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserLogic {
	return &UpdateUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 根据 id 更新用户用户
func (l *UpdateUserLogic) UpdateUser(in *user.UpdateUserRequest) error {
	atoi, err := strconv.Atoi(in.Id)
	if err != nil {
		return err
	}
	err = l.svcCtx.UserModel.Update(l.ctx, &usermodel.User{
		Id:     int64(atoi),
		Name:   in.Name,
		Gender: in.Gender,
	})
	if err != nil {
		return err
	}
	return nil
}
